package repository

import (
	"mon-go-web/internal/database"
	"mon-go-web/internal/models"
)

type UserRepository struct{}

func NewUserRepository() *UserRepository {
	return &UserRepository{}
}

func (ur *UserRepository) Create(user *models.User) int64 {
	tx := database.DB.Create(user)
	if tx.Error != nil {
		panic(tx.Error)
	}
	return tx.RowsAffected
}

func (ur *UserRepository) GetAll() []models.User {
	var users []models.User
	tx := database.DB.Find(&users)
	if tx.Error != nil {
		panic(tx.Error)
	}
	return users
}
